﻿

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Runtime.Serialization;

using WCFService;

namespace WCFHost
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ServiceHost hostStudent = new ServiceHost(typeof(WCFService.StudentService)))
            {
                ServiceHost hostTeacher = new ServiceHost(typeof(WCFService.TeacherService));
                ServiceHost hostTest = new ServiceHost(typeof(WCFService.TestService));
                if (hostStudent.State != CommunicationState.Opening)
                {
                    hostStudent.Open();
                }
                if (hostTeacher.State != CommunicationState.Opening)
                {
                    hostTeacher.Open();
                }
                if (hostTest.State != CommunicationState.Opening)
                {
                    hostTest.Open();
                }
                foreach (var endpoing in hostStudent.Description.Endpoints)
                {
                    System.Console.WriteLine("地址：" + endpoing.Address + "\t绑定名称：" + endpoing.Binding.Name + "\t契约：" + endpoing.Contract.Name);
                }
                foreach (var endpoing in hostTeacher.Description.Endpoints)
                {
                    System.Console.WriteLine("地址：" + endpoing.Address + "\t绑定名称：" + endpoing.Binding.Name + "\t契约：" + endpoing.Contract.Name);
                }
                foreach (var endpoing in hostTest.Description.Endpoints)
                {
                    System.Console.WriteLine("地址：" + endpoing.Address + "\t绑定名称：" + endpoing.Binding.Name + "\t契约：" + endpoing.Contract.Name);
                }

                Console.Read();
                hostStudent.Close();
                hostTeacher.Close();
                hostTest.Close();

            }        

        }

    }

    [DataContract]
    public class Product
    {
        [DataMember]
        public Int32 Id { get; set; }

        [DataMember]
        public string Name { get; set; }
    }


    [DataContract]
    [KnownType(typeof(Order))]
    public class Order
    {
        [DataMember]
        public Int32 Id { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public Product product { get; set; }
    }
    [DataContract]
    public class ListOrder : System.Collections.Generic.List<Order>
    {

    }
}
